package cn.eplato;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;

/**
 * QQ表情 pidgin 表情配置文件生成类
 * @author cutdeer
 * @version 1.0
 * @date 2009/08/03
 */

public class QQFaceTools {
	public static void main(String[] args) throws Exception {
		//先加载QQFaceKey.txt表情快捷键,表情快捷键是对应QQ linux beta1 表情位置的
		InputStream input = QQFaceTools.class.getResourceAsStream("QQFaceKey.txt");
		InputStreamReader isr = new InputStreamReader(input);
		BufferedReader read = new BufferedReader(isr);
		
		List qqkey =new  ArrayList();
		String temp = read.readLine();
		while(temp != null){
			String[] strs = temp.split("/");
			for (int i = 1; i < strs.length; i++) {
				qqkey.add(strs[i]);
			}
			temp = read.readLine();
		}
		
		read.close();
		isr.close();
		input.close();
		
		//读取中文注释 CustomFaceShortcut.xml
		 input = QQFaceTools.class.getResourceAsStream("CustomFaceShortcut.xml");
		 isr = new InputStreamReader(input);
		 read = new BufferedReader(isr);
		
		List qqmark =new  ArrayList();
		temp = read.readLine();
		while(temp != null){
			if(temp.indexOf("/")!= -1 && temp.indexOf(">") == -1){
				qqmark.add(temp.trim().substring(1));
			}
			temp = read.readLine();
		}
		
		read.close();
		isr.close();
		input.close();
		
		//只要前面105个表情
		System.out.println("qqkey leng:"+qqkey.size());
		System.out.println("qqmark leng:"+qqmark.size());
		
		//我在UBUNTU LINUX路径这样写很正常,但好像在WINDOWS会有问题的 ,在WINDOWS你可以把路径写好放到C盘
		String path = QQFaceTools.class.getResource("").getPath();
		System.out.println("生成文件存放路径:"+path);
		OutputStream out = new FileOutputStream(path+"theme");
		OutputStreamWriter osw = new OutputStreamWriter(out);
		BufferedWriter write =new BufferedWriter(osw);
		
		
		write.write("#QQ FACE, AUTHOR:Cutdeer ,site:www.eplato.cn");
		write.newLine();
		write.write("[QQ]");
		write.newLine();
		for (int i = 0; i < qqkey.size(); i++) {
			write.write("# "+i+"  --  "+qqmark.get(i));
			write.newLine();
			write.write(i+".gif    /"+qqkey.get(i));
			write.newLine();
		}
		
		write.close();
		osw.close();
		out.close();
	}
}
